package com.ruoyi.houseClosing.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.houseClosing.domain.TCfContract;
import com.ruoyi.houseClosing.service.TCfContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 房源合同Controller
 *
 * @author ruoyi
 * @date 2021-06-23
 */
@RestController
@RequestMapping("/cfcontract")
public class TCfContractController extends BaseController
{
    @Autowired
    private TCfContractService tCfContractService;

    /**
     * 查询房源合同列表
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:list")
    @GetMapping("/list")
    public TableDataInfo list(TCfContract tCfContract)
    {
        startPage();
        List<TCfContract> list = tCfContractService.selectTCfContractList(tCfContract);
        return getDataTable(list);
    }

    /**
     * 导出房源合同列表
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:export")
    @Log(title = "房源合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCfContract tCfContract) throws IOException
    {
        List<TCfContract> list = tCfContractService.selectTCfContractList(tCfContract);
        ExcelUtil<TCfContract> util = new ExcelUtil<TCfContract>(TCfContract.class);
        util.exportExcel(response, list, "房源合同数据");
    }

    /**
     * 获取房源合同详细信息
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCfContractService.selectTCfContractById(id));
    }

    /**
     * 新增房源合同
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:add")
    @Log(title = "房源合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCfContract tCfContract)
    {
        return toAjax(tCfContractService.insertTCfContract(tCfContract));
    }

    /**
     * 修改房源合同
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:edit")
    @Log(title = "房源合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCfContract tCfContract)
    {
        return toAjax(tCfContractService.updateTCfContract(tCfContract));
    }

    /**
     * 删除房源合同
     */
    @PreAuthorize(hasPermi = "houseClosing:cfcontract:remove")
    @Log(title = "房源合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCfContractService.deleteTCfContractByIds(ids));
    }
}
